package com.emip.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.emip.bean.SiteBean;
import com.emip.bean.UserSitesBean;
import com.emip.dao.BaseDAO;
import com.emip.dao.UserSitesDAO;

@Repository("userSitesDAO")
public class UserSitesDAOImpl extends BaseDAO implements UserSitesDAO {

	public List<UserSitesBean> getSitesByUser(String userid) {
		String[] params = new String[]{userid};
		List<UserSitesBean> result = this.getHibernateTemplate().find("from UserSitesBean m where userid=? order by id", params);
		return result;
	}

	public int add(UserSitesBean entity) {
		Integer id = (Integer) this.getHibernateTemplate().save(entity);
		return id.intValue();
	}

	public void deleteUserSites(String userID) {
		List<UserSitesBean> beans = getSitesByUser(userID);
		for (UserSitesBean bean : beans) {
			this.getHibernateTemplate().delete(bean);
		}
	}

}
